/**
 * 
 */
package com.easidea.tim.service.inventory;

import java.util.Date;
import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.hibernate.Criteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.springside.core.service.EntityService;

import com.easidea.tim.dao.inventory.StorageHistoryDao;
import com.easidea.tim.entity.inventory.StorageHistory;

/**
 * @author Harrison
 *
 */
public class StorageHistoryService extends EntityService<StorageHistory, StorageHistoryDao> {

	private StorageHistoryDao storageHistoryDao;
	
	/**
	 * 
	 * @param pName
	 * @param colorCode
	 * @param sampleFlag
	 * @param startDate
	 * @param endDate
	 * @return
	 */
	public List<StorageHistory> getStorageHistoryList(String pName, String colorCode, Boolean sampleFlag, Date startDate, Date endDate){
		Criteria cte = storageHistoryDao.createUnDeletedCriteria();
		if(StringUtils.isNotBlank(pName)){
			cte.add(Restrictions.eq("productName", pName));
		}
		
		if(StringUtils.isNotBlank(colorCode)){
			cte.add(Restrictions.eq("colorCode", colorCode));
		}
		
		if(sampleFlag != null){
			cte.add(Restrictions.eq("sampleFlag", sampleFlag));
		}
		
		if(startDate != null && endDate != null){
			cte.add(Restrictions.ge("createTime", startDate));
			cte.add(Restrictions.le("createTime", endDate));
		}
		cte.addOrder(Order.desc("productName"));
		List<StorageHistory> lst = (List<StorageHistory>)cte.list();
		return lst;
	}
	
	
	
	/* (non-Javadoc)
	 * @see org.springside.core.service.EntityService#getEntityDao()
	 */
	@Override
	public StorageHistoryDao getEntityDao() {
		return storageHistoryDao;
	}

	/**
	 * @return the storageHistoryDao
	 */
	public StorageHistoryDao getStorageHistoryDao() {
		return storageHistoryDao;
	}

	/**
	 * @param storageHistoryDao the storageHistoryDao to set
	 */
	public void setStorageHistoryDao(StorageHistoryDao storageHistoryDao) {
		this.storageHistoryDao = storageHistoryDao;
	}

}
